<?php
namespace app\common\model;

use think\Session;
use think\Model;

class KwReply extends Model
{
    protected $insert = ['create_time','auid'];

    protected function setCreateTimeAttr(){
        return time();
    }

    protected function setAuidAttr(){
        $wechat_info = session::get('wechat_info');
        return $wechat_info['id'];
    }

    protected function setKeywordListInfoAttr($value){
        return serialize($value);
    }

    protected function setReplyListInfoAttr($value){
        return serialize($value);
    }

    protected function getReplyListInfoAttr($value){
        $html_value = html_entity_decode($value);
        $value = mb_unserialize($html_value);
        return unserialize($value);
    }

    protected function getKeywordListInfoAttr($value){
        return unserialize($value);
    }

    public function showOne($id){
        $result = $this->field('id,name,mode,keyword_list_info,reply_list_info')->find($id);
        return $result;
    }

    public function showList(){
        $wechat_info = session::get('wechat_info');
        $result = $this->field('id,name,keyword_list_info,reply_list_info')->where('auid',$wechat_info['id'])->select();
        
        return $result;
    }
}